package top.fzqblog.service;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.Scheduler;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import top.fzqblog.http.api.RetrofitApi;
import top.fzqblog.model.Meizi;

/**
 * Created by 抽离 on 2017/9/26 0026.
 */

public class RequestService {

    private RetrofitApi retrofitApi;
    public RequestService() {
        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl("http://gank.io/api/")
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
         retrofitApi = retrofit.create(RetrofitApi.class);
    }


    /**
     * rxjava
     * @param subscriber
     * @param category
     * @param num
     * @param page
     */
    public void getMeizi(Subscriber<Meizi> subscriber, String category, int num, int page){
        retrofitApi
                .getMeiziByObserver(category, num, page)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }
}
